import {reqShopCart} from "@/api";

const state = {
    cartList: []
}
const actions = {
    // 获取购物车的数据
    // context中有state、commit、dispatch、getters、
    async getShopCart({commit}) {
        const result = await reqShopCart();
        if (result.code === 200) {
            commit('GETSHOPCART', result.data)
        }
    }
}
const mutations = {
    GETSHOPCART(state, cartList) {
        state.cartList = cartList
    }
}
const getters = {
    cartList(state) {
        return state.cartList[0] || {}
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}